package com.huahang.fashionpress.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huahang.fashionpress.model.Address;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: 阿俊哥
 * @Date: 2019/8/20 15:31
 * @Version 1.0
 *
 * 更新
 * @author : 王翰聪
 * @since : 2019/08/26
 * @version : 1.0
 * 添加了地址的增加删除功能
 */
@Mapper
public interface AddressMapper extends BaseMapper<Address> {
    //查询该用户所有地址
    @Select("select * from t_address where user_id=#{userID}")
    List<Address> selectAllAdress(Integer userID);
    //查询用户所有该状态地址
    @Select("select * from t_address where user_id=#{userID} and address_status=#{addressStatus}")
    List<Address> selectAllAdressByAddressStatus(Integer userID, Integer addressStatus);
    //查询用户所有相同地址位置的地址
    @Select("select * from t_address where user_id=#{userID} and address_place=#{addressPlace} and address_name=#{addressName}")
    List<Address> selectAllAdressByAddressName(Integer userID, String addressPlace, String addressName);

    //添加地址
    @Insert("insert into t_address (address_base, address_place, address_name, address_phone, address_status, user_id)" +
            "values (#{addressBase}, #{addressPlace}, #{addressName}, #{addressPhone}, #{addressStatus}, #{userID})")
    int insertNewAddress(String addressBase, String addressPlace, String addressName, String addressPhone,
                         Integer addressStatus, Integer userID);

    //修改地址addressStatus属性
    @Update("update t_address set address_status=#{addressStatus} where address_id=#{addressID}")
    int updateAdressStatus(Integer addressStatus, Integer addressID);

    //删除一条地址
    @Delete("delete from t_address where address_id=#{addressID}")
    int deleteAddressByAddressID(Integer addressID);
}
